package com.mis.pos.service.impl;

import com.mis.pos.entity.TypeEntity;
import com.mis.pos.repository.TypeRepository;
import com.mis.pos.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author yuxiang
 * @CreatedDate 2019/10/30 18:32
 */
@Service

public class TypeServiceImpl implements TypeService {

    @Autowired
    private TypeRepository classificationRepository;

    @Override
    public TypeEntity findOneById(Long id) {
        return classificationRepository.findClassificationEntityById(id);
    }

    @Override
    public int deletById(Long id) {
        try {
            classificationRepository.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
        return 0;
    }

    @Override
    public TypeEntity findOneByClassNameOrClassNumber(String className, String classNumber) {
        return classificationRepository.findClassificationEntityByClassNameOrClassNumber(className, classNumber);
    }

    @Override
    public int updateEntity(TypeEntity entity) {
        try {
            classificationRepository.updateClassificationEntity(entity.getId(),entity.getClassName(),entity.getClassNumber());
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
        return 0;
    }

    @Override
    public List<String> findAllClassName() {
        return classificationRepository.findAllClassName();
    }
}
